package com.chixing.day03;
/**
 * 方法重载 overloaded
 * (1) 方法名相同
 * (2) 参数列表不一样
 * a.类型不一样
 * b.个数不一样
 * c.顺序不一样
 */
public class OverloadDemo {
    public static void main(String[] args) {
        add(10, 20);
        add(9.9f, 4.5f);
        add(10, 20, 30);

        fun1();
        fun1(10);
        fun1(10, 33, 40);

        int[] arr = {11, 2, 22, 23, 52, 66};
        fun1(arr);
        fun1(null);

        System.out.println(fun1(10, 33, 40));
    }

    //int ... x: int的参数个数不确定
    public static int fun1(int... x) {
        //return 0;
        int sum = 0;
        for (int i = 0; i < x.length; i++) {
            sum += x[i];
        }
        return sum;
    }

    //方法重载
    public static int add(int x, int y) {
        return x + y;
    }

    public static void add(float x, float y) {

    }

    public static void add(int x, int y, int z) {

    }

    public static int add(int x, float y) {
        return 0;
    }
}
